package com.spzx.manager.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.spzx.manager.mapper.CategoryBrandMapper;
import com.spzx.manager.service.CategoryBrandService;
import com.spzx.model.dto.product.CategoryBrandDto;
import com.spzx.model.entity.product.Brand;
import com.spzx.model.entity.product.CategoryBrand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Project: spzx-parent
 * Package: com.spzx.manager.service.impl
 * Version: 1.0
 * <p>
 * Created by  wangjiaxin  on 2024/3/5 01:31
 */
@Service
public class CategoryBrandServiceImpl implements CategoryBrandService {
    @Autowired
    private CategoryBrandMapper categoryBrandMapper;

    /**
     * 分类品牌列表分页查询
     *
     * @param page
     * @param limit
     * @param CategoryBrandDto
     * @return
     */
    @Override
    public PageInfo<CategoryBrand> findByPage(Integer page, Integer limit, CategoryBrandDto CategoryBrandDto) {
        PageHelper.startPage(page, limit);
        List<CategoryBrand> categoryBrandList = categoryBrandMapper.findByPage(CategoryBrandDto);
        return new PageInfo<>(categoryBrandList);
    }

    /**
     * 添加
     *
     * @param categoryBrand
     */
    @Override
    public void save(CategoryBrand categoryBrand) {
        categoryBrandMapper.save(categoryBrand);
    }

    /**
     * 修改
     *
     * @param categoryBrand
     */
    @Override
    public void updateById(CategoryBrand categoryBrand) {
        categoryBrandMapper.updateById(categoryBrand);
    }

    /**
     * 删除
     *
     * @param id
     */
    @Override
    public void deleteById(Long id) {
        categoryBrandMapper.deleteById(id);
    }

    /**
     * 根据分类id查询对应的品牌数据
     *
     * @param categoryId
     * @return
     */
    @Override
    public List<Brand> findBrandByCategoryId(Long categoryId) {
        return categoryBrandMapper.findBrandByCategoryId(categoryId);
    }
}
